package com.iee.collection.list;

import org.apache.commons.collections4.CollectionUtils;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * spring 的 CollectionUtils  和   commons 的 CollectionUtils
 */
public class CollectionUtilss {
    public static void main(String[] args) {
        List<Integer> list = new ArrayList<>();
        list.add(2);
        list.add(1);
        list.add(3);

        /** 判空 */
        if (CollectionUtils.isEmpty(list)) {
            System.out.println("集合为空");
        }
        if (CollectionUtils.isNotEmpty(list)) {
            System.out.println("集合不为空");
        }

        List<Integer> list2 = new ArrayList<>();
        list2.add(2);
        list2.add(4);

        // 并集：
        Collection<Integer> union = CollectionUtils.union(list, list2);
        System.out.println(union);   // [1, 2, 3, 4]
        // 交集
        Collection<Integer> intersection = CollectionUtils.intersection(list, list2);
        System.out.println(intersection);  // [2]
        // 交集的补集
        Collection<Integer> disjunction = CollectionUtils.disjunction(list, list2);
        System.out.println(disjunction);  // [1, 3, 4]
        // 差集
        Collection<Integer> subtractList = CollectionUtils.subtract(list, list2);
        System.out.println(subtractList); // [1, 3]
    }

}
